//
//  XTVisitorTabVC.swift
//  Weibo(Swift)
//
//  Created by 肖霆 on 16/5/11.
//  Copyright © 2016年 肖霆. All rights reserved.
//

import UIKit

class XTVisitorTabVC: UITableViewController {

    //用户是否登录的标记
    var userLogin = XTUserAccountViewModel.sharedUserAccount.isLogin
    
    //参观者视图（即未进行登录时看到的界面）
    var visitorView : XTVisitorView?//设定类型
    
    override func loadView() {
        if userLogin{
        super.loadView()
        }else{
            visitorView = XTVisitorView()
            
            //通过回传闭包将弹出登陆页面的动作传给visitorView
            visitorView?.CallBackClosure = {[weak self] in
            self?.presentOAuthLoginView()
            }
            
            
            
            view = visitorView
            //创建nav按钮
            setupNavUI()
        }
        
        
    }
    
    private func setupNavUI(){
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", fontSize: 15, target: self, action: "registerAction")
    
    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", fontSize: 15, target: self, action: "loginAction")
    
    }
    
    
    //  MARK: - 点击事件 -
    @objc private func registerAction(){
        presentOAuthLoginView()
        
    }

    @objc private func loginAction(){
        presentOAuthLoginView()
    }
    
    private func presentOAuthLoginView(){
        
        let OAuth = XTOAuthTabVC()
        let nav = UINavigationController(rootViewController: OAuth)
        presentViewController(nav, animated: true, completion: nil)
    
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        view.backgroundColor = UIColor.redColor() 用以确认四个控制器是否有效继承
        
    }

}
